package com.linq.cool.beauty.controller;

import com.linq.cool.beauty.domain.BeautyProductCollection;
import com.linq.cool.beauty.service.BeautyProductCollectionService;
import com.linq.cool.common.core.domain.BaseController;
import com.linq.cool.common.core.domain.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: yqlin
 * @Date: 2021/2/9 14:12
 * @Description:
 * @Version: 1.0.0
 */
@RestController
@RequestMapping("productCollection")
public class BeautyProductCollectionController extends BaseController {
    @Autowired
    private BeautyProductCollectionService productCollectionService;

    /**
     * 切换收藏状态
     *
     * @return
     */
    @PostMapping("changeCollection")
    public Result<?> changeCollection(@RequestBody BeautyProductCollection productCollection) {
        productCollectionService.changeCollection(productCollection);
        return Result.ok("收藏成功");
    }

    /**
     * 根据当前用户商品id查询
     *
     * @param productId 商品id
     *
     * @return
     */
    @GetMapping("{productId}")
    public Result<?> getByProductId(@PathVariable("productId") Long productId) {
        return Result.ok(productCollectionService.getByProductId(productId));
    }

    /**
     * 分页查询
     * 前端传递
     *
     * @param current
     * @param size
     *
     * @return
     */
    @GetMapping("list/{current}/{size}")
    public Result<?> list(@PathVariable("current") Long current, @PathVariable("size") long size) {
        return Result.ok(productCollectionService.listByPage(current, size));
    }

}
